/*
    The NeonX Library

    Copyright (c) 2013 darkcat

    Code covered by the MIT License
*/

#pragma once

// nx...
#include "config/general.h"
// nx::thread
#include "platform/thread.h"
// NonCopyable
#include "utility/noncopyable.h"

//////////////////////////////////////////////////////////////////////////
NX_BEG
//////////////////////////////////////////////////////////////////////////

/*
    mutex lock
*/

class Mutex : NonCopyable
{
protected:
    thread::mutex_t mx_;

public:
    Mutex(void)
    {
        thread::mutex_init(mx_);
    }
    virtual ~Mutex()
    {
        thread::mutex_destroy(mx_);
    }

public:
    void lock(void)
    {
        thread::mutex_lock(mx_);
    }
    void trylock(void)
    {
        thread::mutex_trylock(mx_);
    }
    void unlock(void)
    {
        thread::mutex_unlock(mx_);
    }
};

typedef Mutex mutex_t;

//////////////////////////////////////////////////////////////////////////
NX_END
//////////////////////////////////////////////////////////////////////////
